﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using websitephuongthao.Datasql;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

public partial class Dangkygiasu : System.Web.UI.Page
{
    Dataconnection da = new Dataconnection();
    string gt,kv,lblpath,trinhdo,mondaytot,monday;
        String daylop="";
    //DataTableStore dt = new DataTableStore();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        gt = drdgioitinh.SelectedItem.ToString();
        kv = drdkhuvuctinh.SelectedItem.ToString();
        trinhdo = drdtrinhdo.SelectedItem.ToString();
        //mondaytot = drdmondaytot.SelectedItem.ToString()
    }

    public void themdangkylamgiasu()
    {
        for (int i = 0; i < chbcothedaylop.Items.Count; i++)
        {
            if (chbcothedaylop.Items[i].Selected)
            {
                daylop += chbcothedaylop.Items[i].ToString() + ",";
            }
            else
            {
                lblthongbaomonday.Text = "chưa chọn lớp có thể dạy";
            }
        }
        

        for (int i = 0; i < chbmonday.Items.Count; i++)
        {
            if (chbmonday.Items[i].Selected)
            {
                monday += chbmonday.Items[i].ToString() + ",";
            }
            else
            {

                lblthongbaomonday.Text = "chưa chọn lớp có thể dạy";
            }
        }

        for (int i = 0; i < drdmondaytot.Items.Count; i++)
        {
            if (drdmondaytot.Items[i].Selected)
            {
                mondaytot += drdmondaytot.Items[i].ToString() + ",";
                
            }
        }

       

        string strinsert = "insert into GiaSu values(";
        strinsert += "N'" + txthovaten.Text + "',";
        strinsert += "N'" + txtdiachi.Text + "',";
        strinsert += "N'" + txtdienthoaididong.Text + "',";
        strinsert += "N'" + txtdienthoaicodinh.Text + "',";
        strinsert += "N'" + txtemail.Text + "',";
        strinsert += "N'" + txtnamsinh.Text + "',";
        strinsert += "N'" + gt + "',";
        strinsert += "N'" + kv + "',";
        strinsert += "N'" + lblpath + "',";
        strinsert += "N'" + trinhdo + "',";
        strinsert += "N'" + txtnoicongtac.Text + "',";
        strinsert += "N'" + txtnganhhoc.Text + "',";
        strinsert += "N'" + txtkinhnghiem.Text + "',";
        strinsert += "N'" + mondaytot.TrimEnd(',') + "',";
        strinsert += "N'" + daylop.TrimEnd(',') + "',";
        strinsert += "N'" + monday.TrimEnd(',') + "',";
        strinsert += "N'" + txtthongtinkhac.Text + "')";

        if (da.ExcuteQuery(strinsert) > 0)
        {
            lblthongbao.Text = "Đăng ký làm gia sư thành công";
        }
        else
        {
            lblthongbao.Text = "Đăng ký làm gia sư không thành công" + da.Error;
        }
    }
    protected void btndangky_Click(object sender, EventArgs e)
    {
        HttpPostedFile file = fileuploadanhdaidien.PostedFile;
        if (fileuploadanhdaidien.HasFile == false || file.ContentLength > 500000)
        {
            lblthongbao.Text = "Vui lòng chọn file ảnh < 500kb";
        }
        else
        {
            try
            {
                string strpath = Server.MapPath(@"~/HinhAnh/Anhdaidien/" + fileuploadanhdaidien.FileName);
                fileuploadanhdaidien.SaveAs(strpath);
                lblpath = @"~/HinhAnh/Anhdaidien/" + fileuploadanhdaidien.FileName.ToString();
                themdangkylamgiasu();

            }
            catch (Exception ex)
            {
                lblthongbao.Text = "Upload Ảnh không thành công" + ex.Message;

            }
        }
       
    }
    
}